﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

using CSF.BusinessCore.Data;
using Ict.DataAccess;
using Ict.DataAccess.Linq;

namespace CSF.BusinessCore.BLL
{
    /// <summary>
    /// 实现插入时记录创建者和创建时间的业务基类
    /// </summary>
    /// <typeparam name="TEntity">实体类类型</typeparam>
    public abstract class LogCreateLogic<TEntity> : DataEntityLogic<TEntity>
        where TEntity : ILogCreate
    {

        /// <summary>
        /// 使用指定执行器，插入一条新的记录(指定字段更新)
        /// </summary>
        /// <typeparam name="TElement">字段表类型</typeparam>
        /// <param name="t">数据类实例</param>
        /// <param name="selector">字段表</param>
        /// <param name="exec">执行器实例</param>
        /// <returns>是否插入成功</returns>
        public override bool Insert<TElement>(TEntity t, Expression<Func<TEntity, TElement>> selector, Executor exec)
        {
            if (string.IsNullOrWhiteSpace(t.CreateBy))
                throw new NoCreateByException();

            t.CreateTime = DateTime.Now;

            return base.Insert<TElement>(t, selector, exec);
        }
    }
}
